package com.itmg.analyze.jp.url.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

import com.itmg.cache.StaticInformationBean;
import com.itmg.vo.SearchResultItemVO;

/**
 * Amazon 在日本地区所支持的查询类型（SearchIndex）
 * @author Yunhong Chen
 */
public class AmazonSearchIndexBean {
	
	private static HashMap<String,String> all_map_search_index = new HashMap<String,String>();
//	private static HashMap<String,String> baby_map_search_index = new HashMap<String,String>();
//	private static HashMap<String,String> sprots_map_search_index = new HashMap<String,String>();
//	private static HashMap<String,String> game_map_search_index = new HashMap<String,String>();
//	private static HashMap<String,String> kaden_map_search_index = new HashMap<String,String>();
//	private static HashMap<String,String> brand_map_search_index = new HashMap<String,String>();
	
	static{
		all_map_search_index.put("0", "Baby");
		all_map_search_index.put("1", "Books");
		all_map_search_index.put("2", "Music");
		all_map_search_index.put("3", "MusicTracks");
		all_map_search_index.put("4", "SportingGoods");
		all_map_search_index.put("5", "SoftwareVideoGames");
		all_map_search_index.put("6", "VideoGames");
		all_map_search_index.put("7", "Toys");
		all_map_search_index.put("8", "VHS");
		all_map_search_index.put("9", "Video");
		all_map_search_index.put("10", "DVD");
		all_map_search_index.put("11", "Watches");
		all_map_search_index.put("12", "Tools");
	}

	public  AmazonSearchIndexBean() {
		
	}
	
	public static List<SearchResultItemVO> confusionOrder(List<SearchResultItemVO> allAmazonList) {
		
		  Random random = new Random();
		  List<SearchResultItemVO> list = new ArrayList<SearchResultItemVO>();
		  Set<SearchResultItemVO> set = new HashSet<SearchResultItemVO>();
		  int size = allAmazonList.size();
		  if(size>20){
			  while(true){
				  int number = random.nextInt(size);
				  set.add(allAmazonList.get(number));
				  if(set.size()>=20){
					  for(SearchResultItemVO searchResultItemVO : set){
						  list.add(searchResultItemVO);
					  }
					  return list; 
				  }
			  }
		  }
		  else{
			  return allAmazonList; 
		  }
    }
	
	public static HashMap<String,String> getCategoryHashMap(String category){
		return all_map_search_index;
	}
	
	public static List<String> getAmazonType(String category){
		List<String> list = new ArrayList<String>();
		if(category != null){
			String types = StaticInformationBean.getNameByCategory(category, "amazon");
			if(types != null && !"".equals(types)){
				for(String value : types.split(",")){
					list.add(value);
				}
			}
		}
		else{
//			for(String key : all_map_search_index.keySet()){
//				list.add(all_map_search_index.get(key));
//			}
		}
		return list;
		
	}
	

}
